package com.wmm.jinhong;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import java.util.List;

public class HCQRAdapter extends BaseAdapter {
    private Context context;
    private List<GangPingBean> list;
    private LayoutInflater inflater;
    public HCQRAdapter(Context context, List<GangPingBean> list){
        this.context=context;
        this.list=list;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder=null;
        if(convertView==null){
            viewHoder=new ViewHoder();
            convertView=inflater.inflate(R.layout.item_hcqr,null);
            viewHoder.checkBox=convertView.findViewById(R.id.check);
            viewHoder.textView=convertView.findViewById(R.id.txt_gp_code);
            viewHoder.textView2=convertView.findViewById(R.id.txt_is_confirm);
            convertView.setTag(viewHoder);
        }else{
            viewHoder=(ViewHoder) convertView.getTag();
        }
        final GangPingBean bean=list.get(position);
        viewHoder.textView.setText(bean.getGangPingHao());
        viewHoder.checkBox.setChecked(bean.getIsFull().equals("1"));
        viewHoder.textView2.setText(bean.getBackConfirm());
        viewHoder.checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                list.get(position).setIsFull(bean.getIsFull().equals("1")?"0":"1");
                notifyDataSetChanged();
            }
        });
        return convertView;
    }
    class ViewHoder{
        TextView textView;
        CheckBox checkBox;
        TextView textView2;
    }
}
